package com.tanhua.server.controller;

import com.tanhua.server.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author anshuai
 * @create 2021-02-01 20:40
 */
@RestController
@RequestMapping("/comments")
public class CommentsController {

    @Autowired
    private CommentsService commentsService;

    /**
     * 单条动态的评论列表
     * GET /comments
     */
    @GetMapping
    public ResponseEntity findCommentList(String movementId,int page,int pagesize){
        return commentsService.findCommentList(movementId,page,pagesize);
    }

    /**
     * 单条动态-发表评论
     * POST /comments
     */
    @PostMapping
    public ResponseEntity saveComment(@RequestBody Map map){
        //接收参数动态id
        String movementId = (String) map.get("movementId");
        String content = (String) map.get("comment");

        return commentsService.saveComment(movementId,content);

    }

    /**
     * 评论-点赞
     * GET /comments/:id/like
     */
    @GetMapping("/{id}/like")
    public ResponseEntity likeComment(@PathVariable("id") String commentId){
        return commentsService.likeComment(commentId);
    }

    /**
     * 评论-取消点赞
     * GET /comments/:id/dislike
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity disLikeComment(@PathVariable("id") String commentId){
        return commentsService.disLikeComment(commentId);
    }
}
